/* Vue table draggable Hook  */
/* antd vue 版本 table 拖拽 hook  */
/**
 * antd vue 版本 table 拖拽 hook
 * @param list table数据集合
 * @returns customRow 行属性方法
 */
export default function (list: Record<string, any>[]) {
	let ondragIndex
	let ondropIndex
	let dragItem
	const customRow = (record, index) => {
		return {
			draggable: true,
			ondrag() {
				dragItem = record
				ondragIndex = index
			},
			ondrop() {
				ondropIndex = index
			},
			ondragend() {
				if (ondropIndex === undefined) {
					return
				}
				list.splice(ondragIndex, 1)
				list.splice(ondropIndex, 0, dragItem)
				ondropIndex = undefined
			},
			ondragover() {
				return false
			}
		}
	}
	return customRow
}
